package com.zxd.annotation.resolve_annotation;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * ClassName:AnnotationTest
 * Package:com.zxd.annotation.use
 *
 * @Date:2023/10/8 14:34
 * @Author:zxde
 */
public class AnnotationTest {

    @Test
    public void test1() throws Exception{
        Class demoClass = Demox.class;
        Method test1 = demoClass.getDeclaredMethod("test1");


        //isAnnotationPresent(xx.Class)判断当前字节码类对象是否含有xxx注解
        boolean classAnnotationFlag = demoClass.isAnnotationPresent(AnnotationOne.class);
        //获取类上的注解
        Annotation declaredAnnotation = demoClass.getDeclaredAnnotation(AnnotationOne.class);

        //反射获取方法上的注解
        boolean methodAnnotationFlag = test1.isAnnotationPresent(AnnotationOne.class);
        //获取方法上的注解
        AnnotationOne annotation = test1.getAnnotation(AnnotationOne.class);
    }
}
